<?php

class Search_Model_Oemjumpshow extends Apm_Model_Base{

    public function getOemjump($params)
    {

		//セキュアチェック　不正文字列存在時はエラー
		if ($this->CmnF_SecureCheck("all", $params))
		{
			print "セキュアチェックエラー 不正文字".$this->CmnF_SecureCheck("all", $params); //セキュアチェックエラー
			exit();
		} 

		//URL引数を取得
		$strOemId=$params["oem_id"];
		//URL引数チェック(4桁数値以外)
		if (!ereg("^[0-9]{1,4}$",$strOemId))
		{
			print "引数不正エラー";
			exit();
		}
		
//		$strSQLRss="SELECT * FROM T93RSS_SEARCH_PARAM WHERE T93_USER_ID = '".trim($strID_seq)."' AND T93_DATE_ID = '".trim($strID_data)."'";
//		$rsRss = $this->dbGetData($strSQLRss);

		if ($strOemId!="")
		{
			$strSQL="SELECT * ";
			$strSQL=$strSQL."FROM M77OEM_URL ";
			$strSQL=$strSQL."WHERE M77_ID= :oemId";
			$db_params = array('oemId'=>$strOemId);
			//ｸｴﾘ発行(DBｱｸｾｽ)
			$rsSet = $this->dbGetData($strSQL,$db_params);
			if ($rsSet) {

				$SrhKbn_dtl = '01';

				switch (intval($rsSet["M77_PAGE_ID"]))
				{
					case 1:
//						$strOemUrl="../search/SelRailCity.asp";
						$strOemUrl="../shinkensaku/selrailcity/";
						break;
					case 2:
//						$strOemUrl="../search/SelCond.asp";
						$strOemUrl="../shinkensaku/selchoumei/";
						break;
					case 3:
//						$strOemUrl="../search/RstObi.asp";
						$strOemUrl="../rstobi/rstobi/";
						break;
					case 4:
//						$strOemUrl="../double_zero/kensaku/kensaku_select.asp";
						$strOemUrl="../shinkensaku/selrailcity/";
						break;
					case 5:
//						$strOemUrl="../map_search/OemMap.asp";
						$strOemUrl="../search/chizusearch/";
						break;
					default:
						break;
				} 
//				if (intval($rsSet["M77_PAGE_ID"])==4 || intval($rsSet["M77_PAGE_ID"])==5)
				if (intval($rsSet["M77_PAGE_ID"])==5)
				{
					$arrParam=explode(",",$rsSet["M77_PARAMETER"]);
					for ($i=0; $i<count($arrParam); $i=$i+1)
					{
						if (strtolower($arrParam[$i])=="oem_cd")
						{
							$strParam="OemCd";
						} else if (strtolower($arrParam[$i])==strtolower("locationX"))
						{
							$strParam="x";
						} else if (strtolower($arrParam[$i])==strtolower("locationY"))
						{
							$strParam="y";
						} else {
							$strParam=$arrParam[$i];
						}
						$strOemHide=$strOemHide."<input type='hidden' name='".$strParam."' value='".$arrParam[$i+1]."'>"."\r\n";
						$i=$i+1;
					}
				}
				else
				{
					$arrParam=explode(",",str_replace(" ","",$rsSet["M77_PARAMETER"]));
					$strParam="";
					$strParamBk="";
					$strValue="";
					$strValuePref="";
					for ($i=0; $i<count($arrParam); $i=$i+1)
					{
						$strParam=$arrParam[$i];
						if (($strParam)=="get_flag" || ($strParam)=="chiiki" || ($strParam)=="campus" || ($strParam)=="ref_kbn")
						{
						}
/*
						else if (strtolower($strParam)=="pref")
						{
							if ($arrParam[$i+1]!="")
							{
								if (($strValuePref)!="")
								{
									$strValuePref=$strValuePref.",";
								} 
								$strValuePref=$strValuePref.substr("0".$arrParam[$i+1],strlen("0".$arrParam[$i+1])-(2));
							} 
						}
*/
						else
						{
							if (strtolower($strParam)=="oem_cd")
							{
								$item = explode(',', $arrParam[$i+1]);
								$arrParam[$i+1] = $item[0];
								$strParam="OemCd";
							} 
							if (strtolower($strParam)=="eria")
							{
								$strParam="AreaCd";
							} 
							if (strtolower($strParam)==strtolower("t_sentakuCD"))
							{
								$strParam="PrefCd";
							} 
							if (strtolower($strParam)=="sentaku")
							{
								$strParam="SrhKbn";
							} 
							if (strtolower($strParam)=="riyou_kbn")
							{
								$strParam="UseKbn";
							} 
							if (strtolower($strParam)=="rosen")
							{
								$strParam="RailCd";
							} 
							if (strtolower($strParam)=="eki")
							{
								$strParam="StCd";
							} 
							if (strtolower($strParam)=="skchsn")
							{
								$strParam="CityCd";
							} 
							if (strtolower($strParam)=="machi")
							{
								$strParam="SectCd";
							} 
							if (strtolower($strParam)=="place_cd")
							{
								$strParam="PrefCd";
							} 
/*
							if (strtolower($strParam)==strtolower($strParamBk))
							{
								if (($strValue)!="")
								{
									$strValue=$strValue.",";
								} 
								if (strtolower($strParam)=="StCd")
								{
									if (strlen($arrParam[$i+1])>7)
									{
										$strValue=$strValue.substr($arrParam[$i+1],strlen($arrParam[$i+1])-(7));
									}
									else
									{
										$strValue=$strValue.$arrParam[$i+1];
									} 
								}
								else
								{
									$strValue=$strValue.$arrParam[$i+1];
								} 
							}
							else
							{
*/
								if ($i!=0)
								{
									if (($strParamBk == 'PrefCd') || ($strParamBk == 'CityCd')) {
										$strOemHide=$strOemHide."<input type='hidden' name='".$strParamBk."[]' value='".$strValue."'>"."\r\n";
									} else if ($strParamBk == 'SectCd' && in_array($strOemId,array('332','333','334','335'))) {
										$strOemHide=$strOemHide."<input type='hidden' name='TownCd[]' value='".$strValue."'>"."\r\n";
										$SrhKbn_dtl = '05';
									} else if ($strParamBk == 'SrhKbn') {
										$strOemHide=$strOemHide."<input type='hidden' name='".$strParamBk."' value='01'>"."\r\n";
									} else {
										$strOemHide=$strOemHide."<input type='hidden' name='".$strParamBk."' value='".$strValue."'>"."\r\n";
									}
								} 
								$strParamBk=$strParam;
								if (($strParam)=="StCd")
								{
									if (strlen($arrParam[$i+1])>7)
									{
										$strValue=substr($arrParam[$i+1],strlen($arrParam[$i+1])-(7));
									}
									else
									{
										$strValue=$arrParam[$i+1];
									} 
								}
								else
								{
									$strValue=$arrParam[$i+1];
								} 
//							} 
						} 
						$i=$i+1;
					}
				}
				if (($strParamBk == 'PrefCd') || ($strParamBk == 'CityCd')) {
					$strOemHide=$strOemHide."<input type='hidden' name='".$strParamBk."[]' value='".$strValue."'>"."\r\n";
				} else if ($strParamBk == 'SectCd' && in_array($strOemId,array('332','333','334','335'))) {
					$strOemHide=$strOemHide."<input type='hidden' name='TownCd[]' value='".$strValue."'>"."\r\n";
					$SrhKbn_dtl = '05';
				} else if ($strParamBk == 'SrhKbn') {
					$strOemHide=$strOemHide."<input type='hidden' name='".$strParamBk."' value='01'>"."\r\n";
				} else {
					$strOemHide=$strOemHide."<input type='hidden' name='".$strParamBk."' value='".$strValue."'>"."\r\n";
				}
				
				if ((strpos($strOemHide,"PrefCd") ? strpos($strOemHide,"PrefCd")+1 : 0)==0)
				{
					$strOemHidePref=$strOemHidePref."<input type='hidden' name='PrefCd[]' value='".$strValuePref."'>"."\r\n";
				} 
				$strOemHide=$strOemHide."<input type='hidden' name='UseKbn' value='0'>"."\r\n";
				$strOemHide=$strOemHide."<input type='hidden' name='map_tgt' value='0'>"."\r\n";
				$strOemHide=$strOemHide."<input type='hidden' name='seirei' value='0'>"."\r\n";
				if (intval($rsSet["M77_PAGE_ID"])==2) {
					$strOemHide=$strOemHide."<input type='hidden' name='SrhKbn_dtl' value='".$SrhKbn_dtl."'>"."\r\n";
				} else {
					$strOemHide=$strOemHide."<input type='hidden' name='SrhKbn_dtl' value='01'>"."\r\n";
				}
				if (intval($rsSet["M77_PAGE_ID"])==4)
				{
					$strOemHide=$strOemHide."<input type='hidden' name='shikireizero' id='shikireizero' value='on' />"."\r\n";
					$strOemHide=$strOemHide."<input type='hidden' name='shikikin_nashi' id='shikikin_nashi' value='on' />"."\r\n";
					$strOemHide=$strOemHide."<input type='hidden' name='reikin_nashi' id='reikin_nashi' value='on' />"."\r\n";
				}
			}
			else
			{
				$strCaution=1;
			}
		}
		else
		{
			$strCaution=1;
		}
		
		$ret = array('strOemUrl' => $strOemUrl, 'strOemHide' => $strOemHide);
		return $ret;
	}

/*
 * 一応作ってみましたが、使われない可能性がありです by 宮下
 * http://www.apamanshop.com/search/RstObi.jsp?～～でアクセスしてきた場合の処理
 */
    public function getOemobijump($params)
    {
		//セキュアチェック　不正文字列存在時はエラー
		if ($this->CmnF_SecureCheck("all", $params))
		{
			print "セキュアチェックエラー 不正文字".$this->CmnF_SecureCheck("all", $params); //セキュアチェックエラー
			exit();
		}
		
		// 旧SrhKbnに対応
		if (0 == (strcmp('03', $params['SrhKbn']))) {
			$params['SrhKbn'] = '01';
		}
		$strOemHide = '';
		foreach ($params as $key => $val) {
			if ((0 == strcmp('areacd', strtolower($key))) 
			 || (0 == strcmp('prefcd', strtolower($key)))
			 || (0 == strcmp('railcd', strtolower($key)))
			 || (0 == strcmp('citycd', strtolower($key)))
			) {
				$strOemHide=$strOemHide."<input type='hidden' name='".$key."[]' id='".$key."' value='".$val."' />"."\r\n";
			} else {
				$strOemHide=$strOemHide."<input type='hidden' name='".$key."' id='".$key."' value='".$val."' />"."\r\n";
			}
			
		}

		$ret = array('strOemUrl' => '/rstobi/rstobi/', 'strOemHide' => $strOemHide);

		return $ret;
	}

/*
 * http://www.apamanshop.com/shinkensaku/kensaku_select.jsp?～～でアクセスしてきた場合の処理
 */
    public function getKensakuSelectjump($params)
    {
		//セキュアチェック　不正文字列存在時はエラー
		if ($this->CmnF_SecureCheck("all", $params))
		{
			print "セキュアチェックエラー 不正文字".$this->CmnF_SecureCheck("all", $params); //セキュアチェックエラー
			exit();
		}

		$strOemHide = '';
		foreach ($params as $key => $val) {
			if (0 == strcmp('oem_cd', strtolower($key))) {
				$ar_oem_cd = explode(',', $val);  // 「,」で区切られていても最初のcdのみで検索する
				$strOemHide=$strOemHide."<input type='hidden' name='OemCd' id='OemCd' value='".$ar_oem_cd[0]."' />"."\r\n";
			} else if (0 == strcmp('t_sentakucd', strtolower($key))) {
				$strOemHide=$strOemHide."<input type='hidden' name='PrefCd[]' id='PrefCd[]' value='".$val."' />"."\r\n";
			} else {
				$strOemHide=$strOemHide."<input type='hidden' name='".$key."' id='".$key."' value='".$val."' />"."\r\n";
			}
						
		}

		$strOemHide=$strOemHide."<input type='hidden' name='SrhKbn' value='01' />"."\r\n";

		$ret = array('strOemUrl' => '/shinkensaku/selrailcity/', 'strOemHide' => $strOemHide);

		return $ret;
	}
    function CmnF_SecureCheck($value, $params)
	{
		$charactor=array("?","&","%",";","\'","--","<",">","\"");
		$function_ret="";
		
		foreach ($params as $key => $val) {
			if (is_array($val)) {
				$item = $val;
			} else {
				$item[] = $val;
			}
			for ($i=0; $i<=count($charactor); $i=$i+1)
			{
				foreach ($item as $item_val) {
					if ((strpos($item_val,$charactor[$i]) ? strpos($item_val,$charactor[$i])+1 : 0))
					{
						$function_ret=$charactor[$i];
						break;
					}
				}
			}
		}

		return $function_ret;
	} 

}
?>
